<extend name="common:commonTemplate"/>
<block name="main_content">
    <style>
        td {
            text-align: center !important;
        }

        .flag-span {
            display: inline-block;
            float: left;
        }

        .flag {
            display: inline-block;
            width: 20px;
            height: 20px;
            border-radius: 10px;
            float: left;
            margin-left: 5px;
        }

        .flag-grey {
            background: #1e242b
        }

        .flag-green {
            background: green
        }
    </style>
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a class="tip-bottom" href="index.html"
                   data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
                <a href="#">推广人</a> <a class="current" href="#">产品信息列表</a>
            </div>

        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
                            <h5>搜索条件</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <form novalidate="novalidate" id="basic_validate"
                                  name="basic_validate" action="#" method="post"
                                  class="form-horizontal">
                                <div class="control-group">
                                    <label class="control-label">产品型号</label>
                                    <div class="controls">
                                        <input type="hidden" id="group_name" value="{$group_name}">
                                        <input id="txt_product_type" type="text" name="product_type">
                                    </div>
                                </div>

                                <div class="form-actions">
                                    <input id="btn_search" type="button" class="btn btn-success" value="搜索">
                                    <if condition="$group_name eq 'ko_group'">
                                        <a style="background:red" class="btn btn-success"
                                           href="/process/editProduct">新增</a>
                                    </if>

                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title"><span class="icon"> <i class="icon-th"></i> </span>
                            <h5>搜索结果</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <table id="search_result" page_index="1" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>产品型号</th>
                                    <th>芯片</th>
                                    <th>内存</th>
                                    <th>EMMC</th>
                                    <th>BT_WIFI模组</th>
                                    <th>遥控器</th>
                                    <th>HDMI接口</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div id="paging"
                         class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
                        <div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers"
                             id="DataTables_Table_0_paginate">
                            <a page_index="1"
                               class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_first">首页</a>
                            <a class="previous fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_previous">上页</a>
                            <span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span
                                    id="total_page">0</span></span>
                            <a class="next fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_next">下页</a>
                            <a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" style="width:20px;" class="ui-state-default" id="jump_num"></span>

        			<a class="fg-button ui-button ui-state-default" id="DataTables_Table_jump" tabindex="0">跳转</a>
       			</span>
                        </div>
                    </div>


                </div>
            </div>

        </div>


    </div>
</block>

<block name="js_content">
    <script>
        ProductPage = {
            'stopDefault': function (e) {
                //阻止默认浏览器动作(W3C)
                if (e && e.preventDefault)
                    e.preventDefault(e);
                //IE中阻止函数器默认动作的方式
                else
                    window.event.returnValue = false;
                return false;
            },
            'BindEvent': function () {

                $("#txt_product_type").keydown(function(e){
                    var curKey = e.which;
                    if(curKey == 13){
                        $('#btn_search').trigger('click');
                        return false;
                    }
                });

                $('#btn_search').bind('click', function () {
                    var page_index = 1;
                    ProductPage.Search(page_index);
                });

                $('#DataTables_Table_jump').bind('click', function () {
                    var page_index = $('#jump_num').val();
                    if (!isNaN(page_index)) {
                        ProductPage.Search(page_index);
                    } else {
                        alert("跳转必须页必须为数字");
                    }
                });

                $(".first,.previous,.last,.next").bind('click', function () {
                    if ($(this).hasClass('ui-state-disabled')) {
                        return false;
                    }

                    var page_index = $(this).attr('page_index');
                    if (page_index == undefined) {
                        page_index = 1;
                    }
                    //page_index = 1;
                    ProductPage.Search(page_index);
                });
            },
            'Search': function (page_index) {
                var condition = $("#basic_validate").serialize();

                condition += "&pageSize=20&index=" + page_index;

                $.ajax({
                    type: 'post',
                    url: '/AjaxService/center/field/queryProductLine',
                    data: condition,
                    dataType: 'json',
                    async: true,
                    success: function (data) {
                        ProductPage.FillTable(data.Result, page_index);
                        ProductPage.SetPageIndex(data.Result.totalPage, data.Result.totalCount, page_index);


                    },
                    error: function (e, err_name, err_text) {
                        alert(err_text);
                    }
                });

            },
            'convertNull': function (str) {
                if (str) return str;
                return "";
            },
            'FillTable': function (result, page_index) {
                lst_product_en = result.datas;
                var group_name = $("#group_name").val();
                var html = '';
                if (lst_product_en.length > 0) {
                    for (var index in lst_product_en) {
                        var product = lst_product_en[index];
                        var tr_html = "<tr>";
                        tr_html += "<td>" + ProductPage.convertNull(product.product_type) + "<br /></td>";
                        tr_html += "<td>" + ProductPage.convertNull(product.chip) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.ddr) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.emmc) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.bt_wifi) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.remote_control) + "</td>"
                        tr_html += "<td>" + ProductPage.convertNull(product.hdmi) + "</td>"
                        tr_html += "<td style='width: 110px;'>" + ProductPage.formatStatus(product.process_flag) + "</td>"

                        if (group_name && (group_name == 'soft_group'
                                || group_name == 'apply_group'
                                || group_name == 'cp_group'
                                || group_name == 'ko_group')) {
                            tr_html += '<td><div style="text-align:center;"><a style="color:blue;" href="/process/processView?product_id=' + product.id + '">查看详情</a> | <a style="color:blue;" href="/process/editProduct?product_id=' + product.id + '">信息增补</a></div></td>';

                        } else {
                            tr_html += '<td><div style="text-align:center;"><a style="color:blue;" href="/process/processView?product_id=' + product.id + '">查看详情</a></div></td>';
                        }
                        tr_html += "</tr>";
                        html += tr_html;
                    }
                } else {
                    html = '<td style="text-align:center" colspan="10">没查到数据</td>'
                }


                $('#search_result tbody').html('');
                $('#search_result tbody').html(html);

                $('#search_result').attr('page_index', page_index);
            },
            'formatStatus': function (process_flag) {
                //这里先写死
                var group_flags = [1, 2, 4, 8];
                var html = "<span class='flag-span'>";
                for (var i = 0; i < group_flags.length; i++) {
                    if ((process_flag & group_flags[i]) == 0) {
                        html = html + "<span class='flag flag-grey'></span>"
                    } else {
                        html = html + "<span class='flag flag-green'></span>"
                    }
                }
                html += '</span>'
                return html;

            },
            'SetPageIndex': function (total_page, total_count, page_index) {
                $('#total_count').text(total_count);
                $('#total_page').text(total_page);
                $('#curr_page_index').text(page_index);
                page_index = parseInt(page_index);
                total_count = parseInt(total_count);

                if (total_page == 0) {
                    $('#paging .last').addClass('ui-state-disabled');
                    $('#paging .next').addClass('ui-state-disabled');
                    $('#paging .first').addClass('ui-state-disabled');
                    $('#paging .previous').addClass('ui-state-disabled');
                    return;
                }
                if (page_index == 1) {
                    $('#paging .first').addClass('ui-state-disabled');
                    $('#paging .previous').addClass('ui-state-disabled');
                    $('#paging .first').attr('page_index', 1);
                    $('#paging .previous').attr('page_index', 1);
                }
                else {
                    $('#paging .first').removeClass('ui-state-disabled');
                    $('#paging .previous').removeClass('ui-state-disabled');
                    $('#paging .first').attr('page_index', 1);
                    $('#paging .previous').attr('page_index', page_index - 1);
                }

                if (total_page == page_index) {
                    $('#paging .last').addClass('ui-state-disabled');
                    $('#paging .next').addClass('ui-state-disabled');
                    $('#paging .last').attr('page_index', total_page);
                    $('#paging .next').attr('page_index', total_page);
                }
                else {
                    $('#paging .last').removeClass('ui-state-disabled');
                    $('#paging .next').removeClass('ui-state-disabled');
                    $('#paging .last').attr('page_index', total_page);
                    $('#paging .next').attr('page_index', page_index + 1);
                }

            },
            'status_test': function (obj) {
                if (obj == '0') {
                    return '无效';
                } else if (obj == '1') {
                    return '有效';
                }
            }


        };


        $(document).ready(function () {
            ProductPage.BindEvent();
            $('#btn_search').trigger('click');
        });
    </script>
</block>